package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏西西
 * Date: 2023-09-18
 * Time: 14:49
 */
public class IODemo6 {
    //使用一下字节流来读取文件
    public static void main(String[] args) throws IOException {
        //创建InputStream对象的时候，使用绝路劲或者相对路径都可以
        InputStream inputStream = new FileInputStream("d:/aaa.txt");
        //进行读操作
//        while(true){
//            int b = inputStream.read();
//            if(b == -1){
//                //读取完毕
//                break;
//            }
//            System.out.printf("%x  ",(byte)b);
//        }


        while(true){
            byte[] buffer = new byte[1024];
            int len = inputStream.read(buffer);
            System.out.println("len: " +len);
            if(len == -1){
                break;
            }
            for (int i = 0; i < len; i++) {
                System.out.printf("%x\n",buffer[i]);
            }
        }

        inputStream.close();
        }
    }

